//用户管理

layui.config({
  base: '/'
}).extend({
  flying: 'flying'
}).define(['index', 'flying'], function (exports) {
  const $ = layui.$
      ,admin = layui.admin
      ,flying = layui.flying
      ,form = layui.form
      ,table = layui.table
      ,layer = layui.layer
      ,dropdown = layui.dropdown;

  flying.table({
    elem: '#LAY-user-table',
    url: '/system/user/page', //数据接口
    cols: [
      {type: 'numbers', fixed: 'left', title: '序号'}
      , {field: 'userId', title: '用户ID', minWidth: 90}
      , {field: 'username', title: '用户名', minWidth: 90}
      , {field: 'name', title: '姓名', minWidth: 100}
      , {field: 'orgName', title: '所属组织', minWidth: 110}
      , {field: 'mobile', title: '手机', minWidth: 120}
      , {field: 'email', title: '邮箱', minWidth: 160}
      , {field: 'gender', title: '性别', templet: function (d) {
          if (d.gender == 'M') {
            return '<span class="layui-bg-blue layui-badge-rim">男</span>';
          } else if (d.gender == 'F') {
            return '<span class="layui-bg-green layui-badge-rim">女</span>';
          } else {
            return '';
          }
        }, width: 60, unresize: true
      }
      , {field: 'locked', title: '锁定状态', templet: function (d) {
          if (d.locked == 'Y') {
            return '<span class="layui-bg-orange layui-badge-rim">锁定</span>';
          } else if (d.locked == 'N') {
            return '<span class="layui-bg-green layui-badge-rim">正常</span>';
          } else {
            return '';
          }
        }, width: 90, unresize: true
      }
      , {field: 'status', title: '使用状态', width: 90, templet: '#statusSwitchTpl', unresize: true}
      // ,{field: 'picture', title: '头像', width: 100, templet: '#imgTpl'}
      , {field: 'lastLoginTime', title: '最后登录时间', templet: function (d) {
          if (d.lastLoginTime) {
            return layui.util.toDateString(d.lastLoginTime, "yyyy-MM-dd HH:mm:ss");
          } else {
            return '';
          }
        }, minWidth: 170, sort: true, hide: true
      }
      , {field: 'updatedBy', title: '修改人', minWidth: 90}
      , {field: 'updatedTime', title: '修改时间', templet: '<div>{{ layui.util.toDateString(d.updatedTime, "yyyy-MM-dd HH:mm:ss") }}</div>', minWidth: 170, sort: true}
      , {title: '操作', width: 160, align: 'center', fixed: 'right', toolbar: '#user-table'}
    ]
  });

  //对外暴露的接口
  exports('userInfo', {});
});